using System;
using UnityEngine;
using UnityEngine.SceneManagement;

public class AreaSwitch : MonoBehaviour
{
    [SerializeField] private string sceneToLoad;
    [SerializeField] private Transform startPoint;
    [SerializeField] private string transitionName;

    private void Start()
    {
        if (PlayerPrefs.HasKey("Transition"))
        {
            if (PlayerPrefs.GetString("Transition") == transitionName)
            {
                PlayerController.instance.transform.position = startPoint.position;
            }
        }
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            SceneManager.LoadScene(sceneToLoad);
            PlayerPrefs.SetString("Transition", transitionName);
        }
    }
}